<?php

class m_main extends Zmodel{
	
	function select_all_product_ads($num, $offset){
		$this->load->database();
		$sqlstatement="SELECT p.product_id,
            			 	  p.product_name,
            			 	  p.product_desc,
            				  p.price,
            				  p.date_post,
            				  p.date_close,
            				  p.classify_id,
            				  c.classify_desc,
            				  p.user_id,
            				  u.user_login,
            		 		  p.file_path
            			 FROM product_ads AS p INNER JOIN classify_categories AS c ON p.classify_id = c.classify_id 
            			 INNER JOIN users AS u ON p.user_id=u.user_id
            			 ORDER BY p.date_post DESC
          		  	    LIMIT ".$num;
		if($offset==""){
            $sql=$sqlstatement." OFFSET 0";
        }else {
        	$sql=$sqlstatement." OFFSET ". $offset;
        }
        return $this->db->query($sql);
	}
	
	function select_classify_img($pro_id){
	
	$sql="SELECT 
		  p.product_id, 
		  p.user_id, 
		  p.status,
		  p.file_path, 
		  m.img_id,
		  m.img_name
		FROM product_ads as p INNER JOIN product_ads_imgs as m
		ON p.product_id = m.product_id
		WHERE p.product_id=".$pro_id."";
	
	return $this->db->query($sql);
	}
	
	
}

?>